<?php

namespace app\api\controller\v1\user;

use app\Request;
use app\services\user\UserMoneyServices;

class UserWalletController
{

    protected $services;

    public function __construct(UserMoneyServices $services)
    {
        $this->services = $services;
    }

    /**
     * 钱包明细列表
     */
    public function index(Request $request)
    {
        $params = $request->postMore([
            ['pm', ''],
            ['add_time_start', ''],
            ['add_time_end', '']
        ]);
        $user = $request->user()->toArray();
        $params['user_id'] = $user['uid'];

        $result = $this->services->index($params);

        return app('json')->success($result);
    }

    /**
     * 钱包明细信息
     */
    public function info(Request $request)
    {
        $params = [];
        $user = $request->user();
        $params['user'] = $user;

        $result = $this->services->info($params);

        return app('json')->success($result);
    }

    /**
     * 确认提现
     */
    public function confirmCash(Request $request)
    {
        $params = $request->postMore([
            ['amount', ''],
            ['bank_id', 0]
        ]);
        $user = $request->user();
        $params['user'] = $user;

        $this->services->confirmCash($params);

        return app('json')->success(100010);
    }

    /**
     * 提现明细
     *
     * @param Request $request
     * @return \think\Response
     */
    public function cash(Request $request)
    {
        $info = $this->services->cashInfo($request->user());
        return app('json')->success($info);
    }

    public function orders(Request $request)
    {
        $type = $request->get('type', 0);
        $limit = $request->get('limit', 15);

        $list = $this->services->getOrderList($request->user(), $type, $limit);
        return app('json')->success($list);
    }

}